<?php
namespace hid\tests;

class TestCase extends \PHPUnit\Framework\TestCase
{
    protected $config = [];

    /**
     * @var \hid\IdManager
     */
    protected $hid;

    // 单个测试之前(每个测试方法之前调用)
    protected function setUp():void
    {
        $this->config = parse_ini_file(dirname(__DIR__) . '/test.ini');

        $this->hid = new \hid\IdManager([
            'idBuilders'=>[
                'snowflake'=>[
                    'class'=>'hid\builders\SnowflakeBuilder',
                    'workerId'=>1,
                    'datacenterId'=>1,
                    // 'twepoch'=>'',// 起始时间戳
                ],

                'apcuDatabaseSegment'=>[
                    'class'=>'hid\builders\SegmentBuilder',
                    'storage'=>'apcu',
                    'remoteStorage'=>'database',
                    'count'=>10,
                    'step'=>1,
                    'isInitValue'=>true,
                    'initValue'=>1,
                    'preload'=>1
                ],

                'phpDatabaseSegment'=>[
                    'class'=>'hid\builders\SegmentBuilder',
                    'storage'=>'memory',
                    'remoteStorage'=>'database',
                    'count'=>10,
                    'step'=>1,
                    'isInitValue'=>true,
                    'initValue'=>1,
                    'preload'=>3
                ],

                'redisDatabaseSegment'=>[
                    'class'=>'hid\builders\SegmentBuilder',
                    'storage'=>'redis',
                    'remoteStorage'=>'database',
                    'count'=>10,
                    'step'=>1,
                    'isInitValue'=>true,
                    'initValue'=>1,
                    'preload'=>2
                ],

                'phpRedisSegment'=>[
                    'class'=>'hid\builders\SegmentBuilder',
                    'storage'=>'memory',
                    'remoteStorage'=>'redis',
                    'count'=>10,
                    'step'=>1,
                    'isInitValue'=>true,
                    'initValue'=>1,
                    'preload'=>1
                ],

                'apcuRedisSegment'=>[
                    'class'=>'hid\builders\SegmentBuilder',
                    'storage'=>'apcu',
                    'remoteStorage'=>'redis',
                    'count'=>10,
                    'step'=>1,
                    'isInitValue'=>true,
                    'initValue'=>1,
                    'preload'=>2
                ],

                'redisSegment'=>[
                    'class'=>'hid\builders\SegmentBuilder',
                    'storage'=>'memory',
                    'remoteStorage'=>'redis',
                    'count'=>10,
                    'step'=>1,
                    'isInitValue'=>true,
                    'initValue'=>1
                ],

                'database'=>[
                    'storage'=>'database',
                    'isInitValue'=>true,
                    'initValue'=>1,
                ],
                'redis'=>[
                    'storage'=>'redis',
                    'isInitValue'=>true,
                    'initValue'=>1,
                ],

                'apcu'=>[
                    'storage'=>'apcu',
                    'isInitValue'=>true,
                    'initValue'=>1,
                ],

                'php'=>[
                    'storage'=>'memory',
                    'isInitValue'=>true,
                    'initValue'=>1,
                ],

                'db'=>[
                    'storage'=>'db',
                    'isInitValue'=>true,
                    'initValue'=>1,
                ],
            ],

            'storages'=>[
                'redis'=>[
                    'host' => $this->config['redis.host'],
                    'port' => $this->config['redis.port'],
                    'password' => $this->config['redis.password'],
                    'database' => $this->config['redis.database'],
                    'storeKey'=>'redis_{name}',
                    'onConnectManager'=>true
                ],

                'apcu'=>[
                    'storeKey'=>'apcu:{name}',
                ],

                'db'=>[
                    'dsn'=>'mysql:host='.$this->config['db.host'].';dbname='.$this->config['db.dbname'],
                    'username'=>$this->config['db.username'],
                    'password'=>$this->config['db.password'],
                    'storeKey'=>'web_{name}',
                    'onConnectManager'=>false
                ],

                'database'=>[
                    'dsn'=>'mysql:host='.$this->config['db.host'].';dbname='.$this->config['db.dbname'],
                    'username'=>$this->config['db.username'],
                    'password'=>$this->config['db.password'],
                    'table'=>'web_id_generator',
                    'storeKey'=>'db:{name}',
                    'onConnectManager'=>false
                ],
                'memory'=>[
                    'storeKey'=>'{name}',
                ],
            ]
        ]);
    }

    // 单个测试之后(每个测试方法之后调用)
    protected function tearDown():void
    {

    }

    // 整个测试类之前
    public static function setUpBeforeClass():void
    {

    }

    // 整个测试类之前
    public static function tearDownAfterClass():void
    {

    }


}
